package com.qzsoft.zhjd.materiel.modules.materielbatch.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qzsoft.jeemis.common.utils.Result;
import com.qzsoft.zhjd.common.utils.ResultUtils;
import com.qzsoft.zhjd.materiel.modules.materielbatch.dto.MaterielBatchChartDto;
import com.qzsoft.zhjd.materiel.modules.materielbatch.dto.MaterielBatchCountDto;
import com.qzsoft.zhjd.materiel.modules.materielbatch.dto.MaterielBatchListDto;
import com.qzsoft.zhjd.materiel.modules.materielbatch.service.MaterielBatchService;
import com.qzsoft.zhjd.materiel.modules.materieldata.dto.MaterielDataListDto;
import com.qzsoft.zhjd.materiel.modules.materieldata.service.MaterielDataService;

/**
 * @ClassName MaterielBatchController
 * @Description 过磅车次控制器
 * @author linhuawei
 * @since 2022-04-02
 */
@RestController
@RequestMapping("/api/materielBatch")
public class MaterielBatchController {

    @Autowired
    private MaterielBatchService materielBatchService;

    @Autowired
    private MaterielDataService materielDataService;

    /**
     * @Title getCount
     * @Description 获取过磅车次统计信息
     * @param params 查询条件
     * @return 过磅车次统计信息
     */
    @RequiresPermissions("materiel:materielbatch")
    @GetMapping("/getCount")
    public Result<MaterielBatchCountDto> getCount(@RequestParam Map<String, Object> params) {
        MaterielBatchCountDto data = materielBatchService.getCount(params);
        return ResultUtils.ok(data);
    }

    /**
     * @Title getChart
     * @Description 获取过磅车次图表数据
     * @param params 查询条件
     * @return 过磅车次图表数据
     */
    @RequiresPermissions("materiel:materielbatch")
    @GetMapping("/getChart")
    public Result<List<MaterielBatchChartDto>> getChart(@RequestParam Map<String, Object> params) {
        List<MaterielBatchChartDto> data = materielBatchService.getChart(params);
        return ResultUtils.ok(data);
    }

    /**
     * @Title page
     * @Description 过磅车次分页列表
     * @param params 查询条件
     * @return 过磅车次分页列表
     */
    @RequiresPermissions("materiel:materielbatch")
    @GetMapping("/page")
    public Result<IPage<MaterielBatchListDto>> page(@RequestParam Map<String, Object> params) {
        IPage<MaterielBatchListDto> page = materielBatchService.page(params);
        return ResultUtils.ok(page);
    }

    /**
     * @Title details
     * @Description 过磅车次详情信息
     * @param params 查询条件
     * @return 过磅车次详情信息
     */
    @RequiresPermissions("materiel:materielbatch")
    @GetMapping("/details")
    public Result<IPage<MaterielDataListDto>> details(@RequestParam(required = true) String deviceCode,
            @RequestParam(required = true) String day, Integer current, Integer size) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("deviceCode", deviceCode);
        params.put("day", day);
        params.put("current", current);
        params.put("size", size);
        IPage<MaterielDataListDto> page = materielDataService.pageDto(params);
        return ResultUtils.ok(page);
    }

}
